<template>
	<view class="bg">

		<!-- 订单选项 -->
		<!-- 代码重复性高无所谓，能用就行 -->


		<!-- 回收订单信息 -->
		<view class="order-info" :class="selectedTab === 0?'order-infoActive1':'' ">
			<view class="info-item" :class="{ active1: selectedIndex === index }"
				v-for="(info, index) in recycleOrderInfo" :key="index" @tap="selectOrderInfo(index)">
				<text class="text1"> {{ info }} </text>
			</view>
		</view>


		<view class="card-list">
			<view class="card-item" v-for="item in list" v-if="selectedIndex==0" :key="item.id">
				<view class=" card-top" @click="navigateToorderDetails(item.id)">
					<view class="card-text card-text-top">
						<view class="card-dot card-dot-top"></view>
						<text class="address">{{ item.recycleAddress }}</text>
					</view>

					<view class="card-text ">
						<view class="card-left">订单编号：</view>
						<text class="card-right">{{item.id}}</text>
					</view>
					<view class="card-text ">
						<view class="card-left">上门时间：</view>
						<text class="card-right">{{item.scheduledTime}}</text>
					</view>

					<view class="card-text ">
						<view class="card-left">预估重量：</view>
						<text class="card-right">{{item.minWeight + '-' + item.maxWeight + 'Kg'}}</text>
					</view>
					<view class="card-text ">
						<view class="card-left">备&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注：</view>
						<text class="card-right">{{item.remark}}</text>
					</view>

				</view>
				<view class="card-bottom">
					<view class="order-infos">
						<view class="order-item">
							<view class="order-title">距离</view>
							<view class="order-result"><text class="speciltext">{{ item.recycleName }}KM</text>
							</view>
						</view>
						<view class="order-item">
							<view class="order-title">回收品类</view>
							<view class="order-result"><text class="speciltext">{{ item.rubbishCategory }}</text>
							</view>
						</view>
						<view class="order-item">
							<view class="order-title">预估费用</view>
							<view class="order-result"><text class="price">￥{{ item.price }}</text>
							</view>
						</view>
					</view>
					<view class="order-action">
						<image class="clock-icon" src="../../../../static/clock.png"></image>
						<text class="order-time"> {{ item.createTime }}下单</text>
						<view class="action-button" @click="orderReceiving(item.id)">开始接单</view>
					</view>
				</view>
			</view>
		</view>

		<view class="card-list">
			<view class="card-item" v-for="item in OkList" v-if="selectedIndex==1" :key="item.id">
				<view class=" card-top" @click="navigateToorderDetails(item.id)">
					<view class="card-text card-text-top">
						<view class="card-dot card-dot-top"></view>
						<text class="address">{{ item.recycleAddress }}</text>
					</view>

					<view class="card-text ">
						<view class="card-left">订单编号：</view>
						<text class="card-right">{{item.id}}</text>
					</view>
					<view class="card-text ">
						<view class="card-left">上门时间：</view>
						<text class="card-right">{{item.scheduledTime}}</text>
					</view>

					<view class="card-text ">
						<view class="card-left">预估重量：</view>
						<text class="card-right">{{item.minWeight + '-' + item.maxWeight + 'Kg'}}</text>
					</view>
					<view class="card-text ">
						<view class="card-left">备&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注：</view>
						<text class="card-right">{{item.remark}}</text>
					</view>

				</view>
				<view class="card-bottom">
					<view class="order-action">
						<image class="clock-icon" src="../../../../static/clock.png"></image>
						<text class="order-time"> {{ item.createTime }}下单</text>
					</view>
				</view>
			</view>

		</view>

		<view class="card-list">
			<view class="card-item" v-for="item in cancelList" v-if="selectedIndex==2" :key="item.id">
				<view class=" card-top" @click="navigateToorderDetails(item.id)">
					<view class="card-text card-text-top">
						<view class="card-dot card-dot-top"></view>
						<text class="address">{{ item.recycleAddress }}</text>
					</view>

					<view class="card-text ">
						<view class="card-left">订单编号：</view>
						<text class="card-right">{{item.id}}</text>
					</view>
					<view class="card-text ">
						<view class="card-left">上门时间：</view>
						<text class="card-right">{{item.scheduledTime}}</text>
					</view>

					<view class="card-text ">
						<view class="card-left">预估重量：</view>
						<text class="card-right">{{item.minWeight + '-' + item.maxWeight + 'Kg'}}</text>
					</view>
					<view class="card-text ">
						<view class="card-left">备&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注：</view>
						<text class="card-right">{{item.remark}}</text>
					</view>

				</view>
				<view class="card-bottom">
					<view class="order-action">
						<image class="clock-icon" src="../../../../static/clock.png"></image>
						<text class="order-time"> {{ item.createTime }}下单</text>
					</view>
				</view>
			</view>
		</view>

	</view>


	</view>



</template>

<script>
	import OrderApi from '@/common/FindingService/OrderApi.js';
	export default {
		data() {
			return {
				list: [],
				selectedTab: 0, // 默认选中第一个选项卡
				selectedIndex: 0, //选中的按钮变色
				recycleOrderInfo: ['待收取', '已完成', '已取消'],
				cancelList: [],
				show: false,
				userId: '',
				user: {},
				OkList: [],
			}
		},

		onLoad(options) {
			this.selectedIndex = options["selectedIndex"];
		},
		mounted() {

		},
		computed: {

		},
		created() {
			this.userId = uni.getStorageSync('userId');
			this.user = uni.getStorageSync('user');
			this.orderList()
			this.okLists()
			this.cancelLists()

		},
		methods: {
			goToBack() {
				uni.navigateTo({
					url: '/pages/invite/mine/mine'
				})
			},
			//根据门店id查询门店订单
			orderList() {
				OrderApi.queryOrderByStoreId(this.user.storesId).then(res => {
					this.list = res.data.data
					console.log('测试', this.list)
					for (var i = 0; i < this.list.length; i++) {
						var price1 = this.list[i].minWeight * this.list[i].price
						var price2 = this.list[i].maxWeight * this.list[i].price
						this.list[i].price = price1 + '-' + price2 + '元'

						if (this.list[i].remark == '') {
							this.list[i].remark = '无'
						}
						this.list[i].recycleName = this.calculateDistance(this.list[i].recycleLat, this
							.list[i]
							.recycleLon,
							this.list[i].shopLat, this.list[i].shopLon)

					}

				})

			},
			// 查询已完成订单OkList
			//根据骑手id和店铺id查询订单
			okLists() {
				let params = {
					addressId: this.user.storesId,
					recycleId: this.user.id,
					flag: 1
				}
				OrderApi.queryStoreIdUserId(params).then(res => {
					this.OkList = res.data.data
					console.log('已接单', this.OkList)
					for (var i = 0; i < this.OkList.length; i++) {
						var price1 = this.OkList[i].minWeight * this.OkList[i].price
						var price2 = this.OkList[i].maxWeight * this.OkList[i].price
						this.OkList[i].price = price1 + '-' + price2 + '元'

						if (this.OkList[i].remark == '') {
							this.OkList[i].remark = '无'
						}


					}

				})

			},
			cancelLists() {

				OrderApi.cancelStore(this.user.storesId).then(res => {
					this.cancelList = res.data.data
					console.log('已取消', this.cancelList)
					for (var i = 0; i < this.cancelList.length; i++) {
						var price1 = this.cancelList[i].minWeight * this.cancelList[i].price
						var price2 = this.cancelList[i].maxWeight * this.cancelList[i].price
						this.cancelList[i].price = price1 + '-' + price2 + '元'

						if (this.cancelList[i].remark == '') {
							this.cancelList[i].remark = '无'
						}


					}

				})

			},



			// 二级标签转换
			selectOrderInfo(index) {
				this.selectedIndex = index;
			},

			spdd(id) {
				if (id !== null) {
					return {
						color: '#53B68A',
						backgroundColor: '#D0F4E4'
					};
				}
			},

			open() {},
			close() {
				this.show = false
			},


		},
		goto(url) {
			if (!this.user) {
				uni.navigateTo({
					url: '../login/login'
				})
			} else {
				uni.navigateTo({
					url: url
				})
			}

		},
	}
</script>

<style lang="scss" scoped>
	//顶部标题
	.content-title {
		background-color: #fff;
		color: #000;
		font-weight: bold;
		height: 100rpx;
		position: relative;
		font-size: 16px;

		.title-left {
			position: absolute;
			left: 30rpx;
			top: 50%;
			transform: translate(-50%, -50%);
		}

		.title-right {
			text-align: center;
			line-height: 100rpx;
		}
	}

	.card-left {
		font-weight: bold;
	}











	.card-list {
		padding: 0 30rpx;
		margin-top: 20rpx;

		.card-item {
			padding: 0 20rpx;
			border-radius: 16rpx;
			background: #FFFFFF;
			box-shadow: 0px 2px 8px 0px rgba(68, 68, 68, 0.15);
			margin-bottom: 24rpx;

			.card-top {
				border-bottom: 1rpx solid #E4E7ED;
				padding: 20rpx 0;

				.card-text {
					display: flex;
					overflow: hidden;
					font-size: 30rpx;
					color: #333333;
					line-height: 42rpx;
					margin-bottom: 10rpx;

					.card-dot {
						width: 16rpx;
						height: 16rpx;
						border-radius: 50%;
						float: left;
						margin-top: 13rpx;
						margin-right: 10rpx;
					}

					.card-dot-top {
						background: #18B566;
					}

					.card-dot-bottom {
						background: #FA3534;
					}
				}

				.card-text-top {
					margin-bottom: 20rpx;
				}
			}

			.card-bottom {
				padding-bottom: 20rpx;

				.order-infos {
					display: flex;
					padding: 20rpx 0;

					.order-item {
						flex: 1;
						text-align: center;

						.order-title {
							line-height: 1;
							font-size: 28rpx;
							color: #333333;
							margin-bottom: 20rpx;
						}

						.order-result {
							color: #111111;
							font-size: 26rpx;
							line-height: 42rpx;

							.speciltext {
								color: #19BE6B;
								font-size: 32rpx;
							}

							.price {
								color: #FF9900;
							}
						}
					}
				}

				.order-action {
					overflow: hidden;
					height: 74rpx;

					.clock-icon {
						height: 40rpx;
						float: left;
						width: 40rpx;
						margin-top: 17rpx;
						margin-right: 20rpx;
					}

					.order-time {
						color: #AAAAAA;
						font-size: 28rpx;
						float: left;
						line-height: 74rpx;
					}

					.action-button {
						float: right;
						width: 210rpx;
						height: 74rpx;
						background: linear-gradient(90deg, #00C8C6 0%, #00D496 100%);
						fontSize: 30rpx;
						text-align: center;
						line-height: 74rpx;
						border-radius: 12rpx;
						color: #FFFFFF;
					}
				}
			}
		}
	}









	.order-info {
		padding: 10rpx;
		display: flex;
		justify-content: space-around;
		/* background-color: #eee; */
		background-color: #FBFBFB;
		height: 100rpx;

		.info-item {

			/* border: 1px solid #ddd; */
			/* border-radius: 5px; */
			text-align: center;
			margin: 5px;
		}
	}

	.order-infoActive1 .info-item {
		width: 16%;
		font-size: 32rpx;
		/* font-weight: bold; */
		padding: 5rpx;
	}

	.order-infoActive2 .info-item {
		width: 15%;
		font-size: 28rpx;
		/* font-weight: bold; */
		padding-top: 15rpx;
	}

	.order-infoActive3 .info-item {
		width: 20%;
		/* font-weight: bold; */
		font-size: 32rpx;
		padding-top: 13rpx;
	}

	.active1 {
		color: #54C397;
		font-weight: bold;

		/* border-bottom: 6rpx solid #1da25f; */
		.text1 {
			/* text-decoration: underline; */
			padding-bottom: 13rpx;
			border-bottom: 7rpx solid #54C397;
		}
	}

	.just {
		display: flex;
		justify-content: space-between;
		width: 100%;
		align-items: center;
	}

	.order-content {
		font-size: 16px;
		color: #333;
		border: 1px solid #ddd;
		border-radius: 5px;
		background-color: #FBFBFB;
		padding: 0 15rpx;
		height: 100%;

		.order-card1 {
			height: 550rpx;
		}

		.order-card {
			width: 98%;
			font-size: 14px;
			margin: 0 auto;
			margin-bottom: 20rpx;
			padding: 10px;
			/* border: 1px solid rgba(0, 0, 0, 0.5); */
			background-color: white;
			display: flex;
			flex-direction: column;
			box-shadow: -3px 3px 3px rgba(0, 0, 0, .3);
			border-radius: 25rpx;

			.content1 {
				margin: 0 10rpx;
				margin-bottom: 15rpx;
				padding-bottom: 15rpx;
				display: flex;
				justify-content: space-between;
				border-bottom: 1px solid #F3F3F3;

				.text2 {
					display: block;
					width: 120rpx;
					height: 50rpx;
					text-align: center;
					line-height: 50rpx;
					border-radius: 10rpx;
					box-shadow: 3px 3px 3px rgba(0, 0, 0, .3);

					background-color: aliceblue;
					font-Weight: bold;
					color: #BCBCBC;

				}
			}

			.content2 {
				width: 100%;
				display: flex;
				justify-content: space-between;
				/* border-bottom: 1px solid rgba(0, 0, 0, 0.5); */
				margin: 0 10rpx;

				.cot2 {

					.text1 {
						margin-bottom: 20rpx;
						display: flex;

						.text1-left {
							font-weight: bold;
							margin-right: 10rpx;
						}

						.text1-right {
							line-height: 19.2px;
							height: 19.2px;
						}
					}
				}

				.btn {
					font-size: 14px;
					width: 175rpx;
					box-shadow: 3px 3px 3px rgba(0, 0, 0, .3);
				}
			}

			.content3 {
				display: flex;
				flex-direction: row;
				justify-content: space-between;
				margin: 12rpx;
				position: relative;
				border-bottom: 1px solid rgba(0, 0, 0, 0.5);
				background-color: #fafafa;
				word-wrap: break-word;

				.image {
					width: 180rpx;
					height: 180rpx;

				}

				.cot1 {
					display: flex;
					padding-top: 14rpx;
					/* padding-left: 20rpx; */
				}

				.text3 {
					/* line-height: 60rpx; */
				}

				.cot2 {
					width: 450rpx;
					/* margin: 8rpx; */
					height: 60%;
				}

				.cot3 {
					padding: 0rpx 10rpx;
					font-Weight: bold;
					width: 68%;
					position: absolute;
					bottom: 3rpx;
					display: flex;
					justify-content: space-between;

				}
			}

			.content4 {
				margin-left: 10rpx;
				padding-bottom: 10rpx;


				border-bottom: 1px solid #F3F3F3;

				.text1 {
					// font-weight: bold;
					margin-right: 10rpx;
					margin-top: 30rpx;
				}

				.left {
					margin-top: 10rpx;
					margin-bottom: 10rpx;
					width: 150rpx;
				}

				.right {
					margin-left: 30rpx;
				}

			}

			.content5 {
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding: 20rpx 0;
				margin: 0 10rpx;

				.input {
					display: flex;
					align-items: center;

					.textInput {
						font-size: 12px;
						color: #BABABA;
					}
				}

				.text1 {
					padding: 5rpx 10rpx;
					border: 1rpx solid #D2D2D2;
					border-radius: 10rpx;

				}
			}

			.popup {
				// width: 100%;
				padding-top: 100rpx;
				padding-left: 30rpx;
				padding-right: 30rpx;
				height: 700rpx;
				background-color: #fff;

				.jifen {
					// width: 100%;
					font-size: 50px;
					display: flex;
					align-items: center;
					justify-content: center;
				}

				.messege {
					display: flex;
					width: 100%;
					justify-content: space-between;
					padding: 30rpx 0;
					border-bottom: 1px solid #E7E7E7;

					.left {
						font-size: 15px;
						color: #BABABA;
					}

					.right {
						font-size: 15px;
					}
				}

				.btn {
					margin-top: 50rpx;
					background-color: #54C397;
					color: #f8f8f8;
				}
			}
		}
	}
</style>